import requests
import json

url = 'https://api16-normal-sg.tiktokglobalshop.com/api/v2/promotion/search_products'

# 请求参数
params = {
    # 'locale': 'zh-CN',
    # 'language': 'zh-CN',
    'oec_seller_id': '7496123968648743882',
    # 'aid': '6556',
    # 'app_name': 'i18n_ecom_shop',
    # 'fp': 'verify_m88r6xa9_WO4Jit07_CJ0V_4nfM_8we3_KVh9nULaQC6y',
    # 'device_platform': 'web',
    # 'cookie_enabled': 'true',
    # 'screen_width': '1512',
    # 'screen_height': '982',
    # 'browser_language': 'zh',
    # 'browser_platform': 'MacIntel',
    # 'browser_name': 'Mozilla',
    # 'browser_version': '5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36',
    # 'browser_online': 'true',
    # 'timezone_name': 'Asia/Shanghai',
    # 'msToken': 'nY-btaMGJhP0bHdskYD-rD1FXp-QQGw-uMdjrXFLfJkEBlAkM9okk0VXtHYqXFw1IG9Tp9haohXtFXCqst4yJbMHzLS5BTlRX75EH9rFSIP1lORIcOu9dSuPvR4fCSxfaZ7bE3CScQ==',
    # 'X-Bogus': 'DFSzswjudDyV3lGbthp-J2lUrn8F',
    # '_signature': '_02B4Z6wo00001qijv4wAAIDDgach80wIqjaoo6sAAM3Z90'
}

# 请求头
headers = {
    'accept': '*/*',
    'accept-language': 'zh,en-US;q=0.9,en;q=0.8,ja;q=0.7,zh-CN;q=0.6,zh-TW;q=0.5',
    'content-type': 'application/json',
    'origin': 'https://seller.tiktokglobalshop.com',
    'priority': 'u=1, i',
    'referer': 'https://seller.tiktokglobalshop.com/',
    'sec-ch-ua': '"Chromium";v="134", "Not:A-Brand";v="24", "Google Chrome";v="134"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"macOS"',
    'sec-fetch-dest': 'empty',
    'sec-fetch-mode': 'cors',
    'sec-fetch-site': 'same-site',
    'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36',
    # 'x-tt-oec-region': 'MY'
}

# Cookie
cookies = {
    # '_m4b_theme_': 'new',
    # 'passport_csrf_token': '4b8e1602a0ba88971b8fb1f5481c68a1',
    # 'passport_csrf_token_default': '4b8e1602a0ba88971b8fb1f5481c68a1',
    # 'd_ticket': 'b7986c3554f87a31ab110f48d80d2d56d0123',
    # 'store-country-code': '-',
    # 'odin_tt': 'fcd2a10ab29e80c1d24231a417aff7b527939cd55e7a46a5aeba7161172942be',
    # 'store-country-sign': 'MEIEDESNiXJr783LgH6d_gQgNG-zUjIru7orvOS9FNMhg5GzskSH08tr56vPeAJMnGsEEBJyH1glDfE-aL61BoWvxjw',
    # 'sid_tt': 'fd7874cd9ade75997c5d0395c88a3074',
    # 'msToken': 'ysE5YCCa_2_deZoWNweq_hFz_nS2kCjrUaYKmHaTmFkxIbOxpiDzs-13NtpCGgMJuo5cjUGduLEObqyNJXY8kplUQZ74fdtKqyazmwEcaw8pnsuQqw_8kwkazDMcJBYEAt2ZpEO5aQ==',
    # 'sid_guard': 'fd7874cd9ade75997c5d0395c88a3074%7C1743001957%7C864000%7CSat%2C+05-Apr-2025+15%3A12%3A37+GMT',
    # 'sid_ucp_v1': '1.0.0-KGQyZWRmODFiNjE2NDVmNjIwYTQ3YmNjMzE1MGNjMDAzYmE2ODU3NGYKGAiQiKT-jMSm5WcQ5bKQvwYYnDM4AUDrBxADGgJteSIgZmQ3ODc0Y2Q5YWRlNzU5OTdjNWQwMzk1Yzg4YTMwNzQ',
    # 'ssid_ucp_v1': '1.0.0-KGQyZWRmODFiNjE2NDVmNjIwYTQ3YmNjMzE1MGNjMDAzYmE2ODU3NGYKGAiQiKT-jMSm5WcQ5bKQvwYYnDM4AUDrBxADGgJteSIgZmQ3ODc0Y2Q5YWRlNzU5OTdjNWQwMzk1Yzg4YTMwNzQ',
    'sessionid': 'd8a8347fcaf1daaeac755020095ea226',
    # 'sessionid_ss': 'd8a8347fcaf1daaeac755020095ea226',
    # 'ttwid': '1%7Cts0L_2VykDHNNduEvKvrb28-_lKLd1b8V1U-Hvxz1uk%7C1743003430%7Cdd4fb1a490a7945ad42c1faccab8d6dea85f70ff1cf8cbf97689fcd4306d948c',
    # 'uid_tt': '9396df3a150a7e7446c532260c633dcbc15e1cc7461caf6243ea9b741b5cc880',
    # 'uid_tt_ss': '9396df3a150a7e7446c532260c633dcbc15e1cc7461caf6243ea9b741b5cc880',
    # 'user_oec_info': '0a530b84b664a22209454f421bd71983e3f446f0e0738d3019231704264d4d483788e28ff5ad64c1329dfdf270cc592bc87b84a776ffbb03c4ce029feb4ace550e7d76d6e94c476c874d6c054471099d0e9ac250761a490a3c000000000000000000004ecd81ea18f7d9175beacf071dcc52d2908e8983c5e875fdadb3fe0d94f16e98bb8f248c9bdd38d76fdec97d55c580334ebb10de88ed0d1886d2f6f20d2201049d454d43'
}

# 请求数据
data = {
    "page_index": 0,
    "page_size": 1000,
    "promotion_type": 4,
    "pagination_type": 0,
    "search_options": {
        "search_with_exist_discount": {
            "search_period": {
                "start_time": "1743014220",
                "end_time": "1758566220"
            }
        },
        "with_abnormal_check": {
            "seller_promotion_template": 2
        }
    },
    "promotion_type_detail": 11,
    "search_scenario": 1
}

# 发送请求
response = requests.post(url, params=params, headers=headers, cookies=cookies, json=data)
response_data = response.json().get('data', {})
exist_discount_products = response_data.get('exist_discount_product', [])
products = response_data.get('products', [])


# 打印响应结果
print(len(exist_discount_products), len(products))